﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class GenerateSecurityNumber : System.Web.UI.Page
{
    private const String CAPTCHA = "SECURITY_NUMBER";

    protected void Page_Load(object sender, EventArgs e)
    {
        String securityNumber = Generate();
        CaptchaImage.CaptchaImageText ci = new CaptchaImage.CaptchaImageText(securityNumber, 200, 50, "Century Schoolbook");

        this.Response.Clear();

        ImageFormat format = ImageFormat.Jpeg;

        this.Response.ContentType = format.ToString();

        ci.Image.Save(this.Response.OutputStream, format);

        ci.Dispose();

    }

    /// <summary>
    /// Generate security number then store in session
    /// </summary>
    /// <returns>Security number</returns>
    private String Generate()
    {
        String securityNumber;
        securityNumber = Utilities.GenerateRandomCode();

        this.Session[CAPTCHA] = securityNumber;

        return securityNumber;
    }
}